package com.ffcs.crmd.tsp.api.dto.task;

import java.io.Serializable;
import java.util.Map;

import com.ffcs.crmd.tsp.common.base.BaseJobDataMap;
import com.thoughtworks.xstream.annotations.XStreamAliasType;

/**
 * 
 * 功能说明:任务参数数据类
 *
 * @author ZHONGFUHUA
 * 
 * @since 1.0.0-SNAPSHOT
 *
 */
@XStreamAliasType("TspJobDataMap")
public class TspJobDataMap extends BaseJobDataMap<String, Object> implements Serializable{
    
    /**
     * 
     */
    private static final long serialVersionUID = -8120570511992810687L;

    public TspJobDataMap() {
        super();
    }
    
    public TspJobDataMap(Map<String, Object> map) {
        super(map);
    }
    
    // -----------------   put convert ---------------------
    
    public void putAsString(String key, String value) {
        super.put(key, value);
    }
    
    public void putAsString(String key, boolean value) {
        String strValue = Boolean.valueOf(value).toString();
        super.put(key, strValue);
    }
    
    public void putAsString(String key, char value) {
        String strValue = Character.valueOf(value).toString();
        super.put(key, strValue);
    }
    
    public void putAsString(String key, double value) {
        String strValue = Double.toString(value);
        super.put(key, strValue);
    }
    
    public void putAsString(String key, float value) {
        String strValue = Float.toString(value);
        super.put(key, strValue);
    }
    
    public void putAsString(String key, int value) {
        String strValue = Integer.valueOf(value).toString();
        super.put(key, strValue);
    }
    
    public void putAsString(String key, long value) {
        String strValue = Long.valueOf(value).toString();
        super.put(key, strValue);
    }
    
    // -----------------   get convert ---------------------
    
    public String getStringFromString(String key) {
        Object obj = get(key);
        return String.valueOf(obj);
    }
    
    public Integer getIntFromString(String key) {
        Object obj = get(key);
        if(obj != null){
            return new Integer((String) obj);
        }
        return null;
    }
    
    
    public Boolean getBooleanValueFromString(String key) {
        Object obj = get(key);
        if(obj != null){
            return Boolean.valueOf((String) obj);
        }
        return null;
    }
    
    public Character getCharFromString(String key) {
        Object obj = get(key);
        if(obj != null){
            return ((String) obj).charAt(0);
        }
        return null;
    }
    
    public Double getDoubleValueFromString(String key) {
        Object obj = get(key);
        if(obj != null){
            return Double.valueOf((String) obj).doubleValue();
        }
        return null;
    }
    
    public Float getFloatValueFromString(String key) {
        Object obj = get(key);
        if(obj != null){
            return new Float((String) obj).floatValue();
        }
        return null;
    }
    
    public Long getLongValueFromString(String key) {
        Object obj = get(key);
        if(obj != null){
            return new Long((String) obj).longValue();
        }
        return null;
    }
}
